﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;
using System.Data;

public partial class MRP_Customer_ChangePrice : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.Params["type"] != null)
        {
            string xmlFileName = string.Format(@"XML/MRP_ChangePrice_{0}.xml", Request.Params["type"].ToString());
            this.UIServer1.XMLfile = xmlFileName;
            UIServer1.DBAllowInsert = false;
        }
        else
        {
            string xmlFileName = @"XML/MRP_ChangePrice.xml";
            this.UIServer1.XMLfile = xmlFileName;
        }
        if ((Request.Params["MODE"] != null) && (Request.Params["MODE"].ToString().ToLower().Equals("new")))
        if (Request.Params["CustomerID"] != null)
        {
            this.UIServer1.SetFieldValueForNewMode("CustomerID", Request.Params["CustomerID"].ToString());
        }
        if (Request.Params["ProductID"] != null)
        {
            this.UIServer1.SetFieldValueForNewMode("ProductID", Request.Params["ProductID"].ToString());
        }
    }
    protected void UIServer1_DBChange(object sender, Evolutility.UIServer.DatabaseEventArgs e)
    {
        //要根据当前价格的生效期调整价格的失效期
        if (e.Action != Evolutility.UIServer.DBAction.DELETE)
        {

            Database db = DatabaseFactory.CreateDatabase("MRPSqlServer");

            int id = e.ID;

            string sqlCommand = "MRP_ChangeProductPrice";
            DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand);
            db.AddInParameter(dbCommand, "itemID", DbType.Int32, id);
            //db.AddInParameter(dbCommand, "@ErrorRange", DbType.Decimal,1);//假设误差为1%
            int iret = db.ExecuteNonQuery(dbCommand);

        }
        



    }
}
